// pages/order/orderdetail/orderdetail.js
const app = new getApp();
var time = require("../../../utils/util.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    Base: '',
    defaultImg: {},
    order_id: 0,
    order_detail: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let base = app.globalData.siteBaseUrl;
    let defaultImg = app.globalData.defaultImg;

    if (options.id) {
      that.setData({
        Base: base,
        defaultImg: defaultImg,
        order_id: options.id
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    let order_id = that.data.order_id;

    app.sendRequest({
      url: 'api.php?s=order/orderDetail',
      data: {
        order_id: order_id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: "POST",
      success: function (res) {
        let code = res.code;
        let order_detail = res.data;

        if (code == 0) {
          order_detail.create_time = time.formatTime(order_detail.create_time, 'Y-M-D h:m:s')

          that.setData({
            order_detail: order_detail
          })
        }
        console.log(res);
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

  /**
   * 图片加载失败
   */
  errorImg: function (e) {
    let that = this;
    let index = e.currentTarget.dataset.index;
    let defaultImg = that.data.defaultImg;
    let parm = {};

    if (defaultImg.is_use == 1) {
      let parm_key = "order_detail.order_goods_no_delive[" + index + "].picture_info.pic_cover_small";
      parm[parm_key] = defaultImg.value.default_goods_img;

      that.setData(parm);
    }
  },
})